#define _CRT_SECURE_NO_WARNINGS
#include<stddef.h>
struct ListNode
{
    int val;
    struct ListNode* next;
};
struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2)
{
    struct ListNode* head = NULL;
    struct ListNode* tail = NULL;
    while (l1 && l2)
    {
        if (l1->val < l2->val)
        {
            if (head == NULL)
            {
                head = tail = l1;
            }
            else
            {
                tail->next = l1;
                tail = tail->next;
            }
            l1 = l1->next;
        }
        else
        {
            if (head == NULL)
            {
                head = tail = l2;
            }
            else
            {
                tail->next = l2;
                tail = tail->next;
            }
            l2 = l2->next;
        }
    }
    if (l1 == NULL)
    {
        if (head == NULL)
        {
            tail = head = l2;
        }
        else
        {
            tail->next = l2;
        }

    }
    else
    {
        if (head == NULL)
        {
            tail = head = l1;
        }
        else
        {
            tail->next = l1;
        }
    }
    return head;
}
struct ListNode* reverseList(struct ListNode* head)
{

    struct ListNode* newhead = NULL;
    struct ListNode* cur = head;
    while (cur)
    {
        struct ListNode* next = cur->next;
        cur->next = newhead;
        newhead = cur;
        cur = next;

    }
    return newhead;
}
